package com.xxxy.ljh.myapplication.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.xxxy.ljh.myapplication.R;
import com.xxxy.ljh.myapplication.Dao.MemberApplicationDao;
import com.xxxy.ljh.myapplication.DaoImpl.MemberApplicationDaoImpl;
import com.xxxy.ljh.myapplication.model.MemberApplication;
import com.xxxy.ljh.myapplication.Adapter.ApplicationReviewAdapter;

import java.util.List;

/**
 * 社团申请审核活动页面
 * 用于展示和处理社团成员申请的审核操作
 */
public class ClubApplicationReviewActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private ApplicationReviewAdapter adapter;
    private MemberApplicationDao applicationDao;
    private int clubId;
    private List<MemberApplication> applications;

    /**
     * Activity创建时的回调方法
     * 初始化界面布局，获取传递的社团ID，初始化数据访问对象并加载申请数据
     * @param savedInstanceState 保存的实例状态Bundle对象
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_club_application_review);

        // 获取传递的社团ID参数
        clubId = getIntent().getIntExtra("club_id", -1);

        // 检查社团ID是否有效
        if (clubId == -1) {
            Toast.makeText(this, "无效的社团信息", Toast.LENGTH_SHORT).show();
            finish();
            return;
        }

        initViews();
        applicationDao = new MemberApplicationDaoImpl(this);
        loadApplications();
    }

    /**
     * 初始化界面视图组件
     * 设置RecyclerView的布局管理器
     */
    private void initViews() {
        recyclerView = findViewById(R.id.recyclerView_applications);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }

    /**
     * 加载社团申请数据
     * 从数据库获取指定社团的待审核申请列表，并设置适配器
     */
    private void loadApplications() {
        applications = applicationDao.getPendingApplicationsByClubId(clubId);
        adapter = new ApplicationReviewAdapter(this, applications);
        recyclerView.setAdapter(adapter);
    }
}

